#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_set>
#include<bits/stdc++.h>
#define fi first
#define se second
#define SIZE(x) ((int)x.size())
#define out(x) cerr<<#x<<" = "<<(x)<<endl;
#define MP(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
#define VI vector<int>
#define VVI vector< vector<int> >
#define VL vector<ll>
#define VVL vector<VL >
#define VC vector<char>
#define PI pair<int,int>
#define PL pair<ll,ll>
#define EPS 0.0000001


inline int lson(int x){return x<<1;}
inline int rson(int x){return (x<<1)|1;}

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
	return x*f;
}

template<typename T> 
inline void read(T &x){
	x=0;T f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}


//#define INF 5340172838076674L
#define INF 1000000000
#define MOD 1000000007

struct node{
	int a,b;
	bool operator<(const node& x)const{
		if(a!=x.a)return a<x.a;
		return b>x.b;
	};
};

VVL mat_mul(VVL &a,VVL &b){
	int n=a.size();
	VVL res(n,VL(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++)
				res[i][j]=(res[i][j]+a[i][k]*b[k][j])%MOD;
		}
	}
	return res;
}

VVL mat_qm(VVL &m,ll k){
	int n=m.size();
	VVL res(n,VL(n)),tmp=m;
	for(int i=0;i<n;i++)res[i][i]=1;
	while(k){
		if(k&1)res=mat_mul(res,tmp);
		k>>=1;
		tmp=mat_mul(tmp,tmp);
	}
	return res;
}

int main(){
    #ifdef BUG
    freopen("a.in","r",stdin);
    #endif
	ll n=read(),k;
	read(k);
	VVL mat=VVL(n,VL(n));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			mat[i][j]=read();
	VVL res=mat_qm(mat,k);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			printf("%d ",res[i][j]);
		}
		printf("\n");
	}
}